define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'esign/index' + location.search,
                    add_url: 'esign/add',
                    // edit_url: 'esign/edit',
                    del_url: 'esign/del',
                    multi_url: 'esign/multi',
                    import_url: 'esign/import',
                    table: 'esign',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'phone',
                            title: __('Phone'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'card_type',
                            title: __('Card_type'),
                            searchList: {
                                "CRED_PSN_CH_IDCARD": __('Card_type CRED_PSN_CH_IDCARD'),
                                "CRED_PSN_CH_TWCARD": __('Card_type CRED_PSN_CH_TWCARD'),
                                "CRED_PSN_CH_MACAO": __('Card_type CRED_PSN_CH_MACAO'),
                                "CRED_PSN_PASSPORT": __('Card_type CRED_PSN_PASSPORT'),
                                "CRED_PSN_CH_GREEN_CARD": __('Card_type CRED_PSN_CH_GREEN_CARD'),
                                "CRED_PSN_UNKNOWN": __('Card_type CRED_PSN_UNKNOWN')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'card_no', title: __('Card_no')},
                        {
                            field: 'doc_type',
                            title: __('合同类型'),
                            searchList: {
                                1: __('培训协议'),
                                2: __('就业指导合作协议'),
                                3: __('终止服务协议'),
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'doc_name',
                            title: __('Doc_name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {field: 'doc_file', title: __('Doc_file'), operate: false, formatter: Table.api.formatter.file},
                        {
                            field: 'follow_id',
                            title: __('Follow_id'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        // {field: 'account_id', title: __('Account_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'esign', title: __('Esign'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'org_id', title: __('Org_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {
                                "wait": __('Status wait'),
                                "over": __('Status over'),
                                "fail": __('Status fail')
                            },
                            formatter: Table.api.formatter.status
                        },
                        {field: 'sign_url', title: __('Sign_url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'esign/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'esign/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'esign/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
